﻿using System;
using System.Collections.Generic;
using System.Linq;

using Fuse8.DomainFramework.BusinessService;
using Fuse8.DomainFramework.Common;
using Fuse8.DomainFramework.Common.Locator;

using Fuse8.ContentManagementFramework.Domain.Special;
using Fuse8.ContentManagementFramework.Domain.Commands;
using Fuse8.ContentManagementFramework.Domain.Commands.CommandParameters;
using Fuse8.ContentManagementFramework.Domain;

namespace Fuse8.ContentManagementFramework.BizFacade.Services
{
    public class CmsEntityMetaInformationService : BaseBusinessService<CmsEntityMetaInformation, int>
    {        
        public virtual CmsEntityMetaInformation GetMetaForEntity(CmsComplexEntityObject entity)
        {
            Guard.ArgumentNotNull(entity, "entity");

            var command = DependencyServiceLocator.Current.GetInstance<CmsEntityMetaGetInformationCommand>();

            var commandParameter = new CmsEntityMetaGetInformationCommandParameter()
                {
                    EntityId = entity.IsCreated ? entity.Id : new Nullable<int>(),
                    EntityTypeKey = entity.TypeParameter
                };

            command.ConfigureCommand(commandParameter);

            return FindOne(command);
        }
    }
}
